/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui.RRHH;

import Atxy2k.CustomTextField.RestrictedTextField;
import Controlador.Bean.Almacen.TipoProducto;
import Controlador.Bean.RRHH.Personal;
import Controlador.Bean.Seguridad.Perfil;
import Controlador.Bean.Seguridad.PerfilxUsuario;
import Controlador.Bean.Seguridad.Pregunta;
import Controlador.Bean.Seguridad.Usuario;
import Controlador.Service.Seguridad.ServicioPerfil;
import gui.Compras.agregarCatalogo;
import gui.General.Main;
import lib.Validaciones;
import java.util.List;
import javax.swing.JButton;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import java.awt.Component;
import java.util.ArrayList;
import java.util.List;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;



/**
 *
 * @author david
 */
public class NuevoEmpleado extends javax.swing.JInternalFrame {

     
    public class MyActionListener implements ActionListener {

        @Override
        public void actionPerformed(ActionEvent evt) {
            JComboBox cb = (JComboBox) evt.getSource();
            Object selected = cb.getSelectedItem();

            if (selected.toString().equals("OPERADOR")) {

                // JTextField txtUser = new JTextField(16);
                jPanelUsuario.setVisible(false);
//                lblUsuario.setVisible(false);
//                lblPassword.setVisible(false);
//                lblPerfil.setVisible(false);
//                cmbPerfil.setVisible(false);
//                txtUsuario.setVisible(false);
//                txtPassword.setVisible(false);


            } else if (selected.toString().equals("ADMINISTRADOR")) {

                if (ServicioPerfil.verificarPermiso(Main.usu.getIdUsuario(), "SEGCRUSU", "ACC000")) {


                    jPanelUsuario.setVisible(true);

                    perfiles = (ArrayList<Perfil>) Controlador.Service.Seguridad.ServicioPerfil.seleccionarTodo();
                    cmbPerfil.removeAllItems();
                    cmbPerfil.addItem("Seleccionar");
                    for (int i = 0; i < perfiles.size(); i++) {
                        cmbPerfil.addItem(perfiles.get(i).getNombre());

                    }

//                lblUsuario.setVisible(true);
//                lblPassword.setVisible(true);
//                lblPerfil.setVisible(true);
//                cmbPerfil.setVisible(true);
//                txtUsuario.setVisible(true);
//                txtPassword.setVisible(true);

                } else {
                  
                    mensaje();
      
                }

            }

        }
    }

    

    /**
     * Creates new form detalleEmpleado
     */

    private TableModel tb;
    int clic=0;
    String selectedId;
    String tipo;
    private ArrayList<Perfil> perfiles;
    public static ArrayList<Pregunta> preguntas = (ArrayList<Pregunta>) Controlador.Service.Seguridad.ServicioSeguridad.seleccionarPreguntas();
    private int valUsuario = 0;
    
    public NuevoEmpleado(String Empleado) {
        initComponents();
        initComp();
        
    }
    
  private static NuevoEmpleado myne=null;
   
    
  public static NuevoEmpleado getInstance() {
         if(myne == null){
                       myne = new NuevoEmpleado("");    
            Main.getDesktop().add(myne); 
            myne.setVisible(true);
               myne.toFront();           
                    }
                    else{
                        if (myne.isClosed()|| !myne.isVisible()) {
                                myne = new NuevoEmpleado(""); 
                                Main.getDesktop().add(myne);
                                myne.toFront();
                                myne.setVisible(true);
                        }
                        else
                            myne.toFront();
                    }
        
        
        
                return myne;
    }
    
  private void mensaje(){
      
      cmbTipoEmp.setSelectedItem("SELECCIONAR");
      JOptionPane.showMessageDialog(this, "Usted no tiene permisos para crear usuarios");
      
      
  }
  
    private void initComp(){
    
        tb = new TableModel();
        tblEmpleados.setModel(tb);
        tblEmpleados.setRowSelectionAllowed(true);
        txtIdEmpleado.setEditable(false);
        jPanelUsuario.setBorder(javax.swing.BorderFactory.createTitledBorder("Usuario"));
        jPanelUsuario.setVisible(false);
        cmbHorario.removeAllItems();
        
        Calendar cal = Calendar.getInstance(); 
        cal.setTime(new Date()); 
        cal.add(Calendar.YEAR, -18); 
       fechaNac.getMonthView().setUpperBound(cal.getTime());
       fechaNac.getMonthView().setLowerBound(null);
       
       fechaNac.setDate(cal.getTime());
        
        
        cmbHorario.addItem("SELECCIONAR");
        cmbHorario.addItem("MAÑANA");
        cmbHorario.addItem("NOCHE");
        
        cmbTipoEmp.removeAllItems();
        cmbTipoEmp.addItem("SELECCIONAR");
        cmbTipoEmp.addItem("ADMINISTRADOR");
        cmbTipoEmp.addItem("OPERADOR");
        buttonGroup1.add(radioDni);
        buttonGroup1.add(RadioCarnetExtranjeria);
     
//       RestrictedTextField r = new RestrictedTextField(txtNumeroDocumento);
//             r.setLimit(8);
        
        cmbPregunta.removeAllItems();
        cmbPregunta.addItem("Seleccionar");
            for(int i=0; i<preguntas.size(); i++){
             cmbPregunta.addItem(preguntas.get(i).getPregunta());
      
        }
      
     MyActionListener actionListener = new MyActionListener();
     cmbTipoEmp.addActionListener(actionListener);
     
    

    RestrictedTextField r = new RestrictedTextField(txtNumeroDocumento);
    r.setLimit(11);
     
     tblEmpleados.setDefaultRenderer(JButton.class, new MiRender());
     tblEmpleados.setDefaultEditor(JButton.class, new MiEditor());
      
        
        
        
    }
    
    
   String id;
   String nombre;
       
    public void filtrar(String id){ //metodo para actualizar directamente
        this.id = id;
         tb.actualizarTabla();
    }
    
    
      public void filtrar2(String id, String nombre){ // metodo para busquedas
        this.id = id;
        this.nombre = nombre;
         tb.actualizarTabla2();
    }
    
    
      class TableModel extends AbstractTableModel{
        
        //Two arrays used for the table data
        String[] columnNames = {"ID","Nombre", "Ape Paterno", "Ape Materno" , "Num Doc", "Fecha Nac", "Estado", "Horario", "Tipo", "Eliminar"};
        //String[] columnNames = {"ID","Nombre", "Ape Paterno", "Ape Materno" , "Num Doc", "Fecha Nac", "Estado", "Eliminar"};
               
        public List<Personal> data = Controlador.Service.RRHH.GestionRRHH.obtenerPersonal();
        
        
       //public List<Personal> data;
        
        public void actualizarTabla(){
            data = Controlador.Service.RRHH.GestionRRHH.obtenerPersonal();
            
            fireTableDataChanged();
            gui.RRHH.DetalleEmpleado1.tb.actualizarTabla();
        }
        
       
        
         public void actualizarTabla2(){ //para las busquedas
            data = Controlador.Service.RRHH.GestionRRHH.filtrarPersonal2(id, nombre);
   
             //data = Controlador.Service.Almacen.GestionAlmacenes.filtrarProductos(id, nombre);
            fireTableDataChanged();
            gui.RRHH.DetalleEmpleado1.tb.actualizarTabla();
        }
        
        @Override
        public int getRowCount()
        {
            return data.size();
        }
        
        
        
        @Override
        public int getColumnCount()            
        {
            return columnNames.length;
        }
         //
        
        @Override
        public Object getValueAt(int row, int column)
        {   
            switch(column){
                case 0: return data.get(row).getIdEmpleado();
                case 1: return data.get(row).getNombre(); 
                case 2: return data.get(row).getApellidoPaterno();
                case 3: return data.get(row).getApellidoMaterno();
                case 4: return data.get(row).getNumeroDocumento();
                case 5: return data.get(row).getFechaNacimiento();
                case 6: return data.get(row).getEstado();
                case 7: 
                    if (data.get(row).getTurno().equals("HOR000001")) {
                        return "MAÑANA";
                    } else {
                        return "NOCHE";
                    }
                case 8:  
                    {

                    String SacaId = (data.get(row).getIdEmpleado().substring(0, 3));

                    //System.out.println(SacaId);
                    if (SacaId.equals("EMP")) {
                        return "OPERADOR";
                       
                    } else if (SacaId.equals("ADM")) {
                         return "ADMINISTRADOR";
                    }
                }
                    
                default: return new JButton("Eliminar");
            }
        }
        
        //Used by the JTable object to set the column names
        @Override
        public String getColumnName(int column) {
            return columnNames[column];
        }
        
        //Used by the JTable object to render different
        //functionality based on the data type
        @Override
        public Class getColumnClass(int c) {
            if(c!=9){
            return getValueAt(0, c).getClass();
            }else{
                return JButton.class;
            }
        }
        
        @Override
        public boolean isCellEditable(int row, int column)
        {
	        return false;
        }
        
     }
       public class MiRender implements TableCellRenderer {
        // Este metodo indica como debe de pintarse el elemento en la fila row, en la columna column
        // que esta en la tabla table y tiene el color dado por el objeto.
        @Override
        public Component getTableCellRendererComponent(JTable table, Object color, boolean isSelected, boolean hasFocus, int row, int column) {    
            // como el boton y el calendario son componentes esto se vale.
            return (JComponent)table.getValueAt(row, column);
        }
     }
     
     public class MiEditor extends AbstractCellEditor implements TableCellEditor {
         private Boolean currentValue;
         @Override
         public Object getCellEditorValue()
         {
            return currentValue;
         }
         //El editor usara el propio componente. Para que funcione la celda en el modelo debe ser editable.
         @Override
         public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column)
         {
           return (JComponent) value;// la tabla solo debe tener componentes graficos
         }
     }
    
      
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblEmpleados = new javax.swing.JTable();
        btnLimpiar = new javax.swing.JButton();
        jpanel2 = new javax.swing.JPanel();
        txtApellidoPaterno = new javax.swing.JTextField();
        txtNumeroDocumento = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jlabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        radioDni = new javax.swing.JRadioButton();
        RadioCarnetExtranjeria = new javax.swing.JRadioButton();
        txtApellidoMaterno = new javax.swing.JTextField();
        cmbTipoEmp = new javax.swing.JComboBox();
        cmbHorario = new javax.swing.JComboBox();
        fechaNac = new org.jdesktop.swingx.JXDatePicker();
        jLabel1 = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtIdEmpleado = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jPanelUsuario = new javax.swing.JPanel();
        lblUsuario = new javax.swing.JLabel();
        lblPassword = new javax.swing.JLabel();
        lblPerfil = new javax.swing.JLabel();
        txtUsuario = new javax.swing.JTextField();
        cmbPerfil = new javax.swing.JComboBox();
        txtPassword = new javax.swing.JPasswordField();
        txtRespuesta = new javax.swing.JTextField();
        cmbPregunta = new javax.swing.JComboBox();
        jLabel2 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        btnCheck = new javax.swing.JButton();
        btnGuardar = new javax.swing.JButton();
        btnBuscar = new javax.swing.JButton();

        setClosable(true);
        setTitle("Nuevo Empleado");

        tblEmpleados.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        tblEmpleados.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"Juan Carlos", "Salas Delgado", "44600443", "Jc2013@hotmail.com"},
                {"Pedro Leon", "Dias Benites", "33345331", "Pedro_Leon@gmail.com"},
                {"David Antonio", "Fuentes Ferrando", "49385938", "DaFuentes@gmail.com"},
                {"Gabriella", "Rodriguez Quiñones", "44682915", "GabRodr@yahoo.com"}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblEmpleados.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblEmpleadosMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tblEmpleados);
        tblEmpleados.getAccessibleContext().setAccessibleName("Empleados");

        btnLimpiar.setText("Limpiar");
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        jLabel3.setText("Apellido Paterno:");

        jlabel6.setText("Nombre:");

        jLabel7.setText("Tipo documento:");

        jLabel8.setText("Numero Documento:");

        radioDni.setText("DNI");

        RadioCarnetExtranjeria.setText("Pasaporte");

        cmbTipoEmp.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbTipoEmp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbTipoEmpActionPerformed(evt);
            }
        });

        cmbHorario.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbHorario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cmbHorarioActionPerformed(evt);
            }
        });

        fechaNac.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fechaNacActionPerformed(evt);
            }
        });

        jLabel1.setText("Apellido Materno:");

        jLabel4.setText("Fecha Nacimiento:");

        jLabel5.setText("IdEmpleado:");

        jLabel6.setText("Tipo de Trabajador:");

        jLabel9.setText("Horario:");

        lblUsuario.setForeground(new java.awt.Color(255, 51, 0));
        lblUsuario.setText("Usuario:");

        lblPassword.setForeground(new java.awt.Color(255, 0, 0));
        lblPassword.setText("Password:");

        lblPerfil.setForeground(new java.awt.Color(255, 51, 0));
        lblPerfil.setText("Perfil:");

        cmbPerfil.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        txtPassword.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtPasswordActionPerformed(evt);
            }
        });

        cmbPregunta.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel2.setForeground(new java.awt.Color(255, 51, 0));
        jLabel2.setText("Pregunta:");

        jLabel10.setForeground(new java.awt.Color(255, 51, 0));
        jLabel10.setText("Respuesta");

        btnCheck.setBackground(new java.awt.Color(255, 0, 0));
        btnCheck.setText("chek");
        btnCheck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCheckActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelUsuarioLayout = new javax.swing.GroupLayout(jPanelUsuario);
        jPanelUsuario.setLayout(jPanelUsuarioLayout);
        jPanelUsuarioLayout.setHorizontalGroup(
            jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelUsuarioLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addGroup(jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblPerfil)
                    .addComponent(lblPassword)
                    .addComponent(jLabel2)
                    .addComponent(jLabel10)
                    .addComponent(lblUsuario))
                .addGap(43, 43, 43)
                .addGroup(jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(cmbPregunta, javax.swing.GroupLayout.Alignment.LEADING, 0, 101, Short.MAX_VALUE)
                    .addComponent(cmbPerfil, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtPassword, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtUsuario, javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtRespuesta))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnCheck)
                .addContainerGap())
        );
        jPanelUsuarioLayout.setVerticalGroup(
            jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelUsuarioLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblUsuario)
                    .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnCheck))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPassword)
                    .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblPerfil)
                    .addComponent(cmbPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addGroup(jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cmbPregunta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addGroup(jPanelUsuarioLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtRespuesta, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addContainerGap())
        );

        javax.swing.GroupLayout jpanel2Layout = new javax.swing.GroupLayout(jpanel2);
        jpanel2.setLayout(jpanel2Layout);
        jpanel2Layout.setHorizontalGroup(
            jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanel2Layout.createSequentialGroup()
                .addGap(44, 44, 44)
                .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jlabel6)
                        .addComponent(jLabel5)
                        .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel7)
                        .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addComponent(jLabel8))
                .addGap(54, 54, 54)
                .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtIdEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtApellidoPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtApellidoMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jpanel2Layout.createSequentialGroup()
                        .addComponent(radioDni)
                        .addGap(18, 18, 18)
                        .addComponent(RadioCarnetExtranjeria))
                    .addComponent(txtNumeroDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jpanel2Layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6)
                            .addComponent(jLabel9))
                        .addGap(36, 36, 36)
                        .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cmbTipoEmp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(fechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cmbHorario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(48, 48, 48))
                    .addGroup(jpanel2Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jPanelUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(55, Short.MAX_VALUE))
        );
        jpanel2Layout.setVerticalGroup(
            jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(fechaNac, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(txtIdEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel5)))
                .addGap(4, 4, 4)
                .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpanel2Layout.createSequentialGroup()
                        .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlabel6))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(txtApellidoPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtApellidoMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel1))
                        .addGap(13, 13, 13)
                        .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(radioDni)
                                .addComponent(RadioCarnetExtranjeria)))
                        .addGap(18, 18, 18)
                        .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtNumeroDocumento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8)))
                    .addGroup(jpanel2Layout.createSequentialGroup()
                        .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jpanel2Layout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel6))
                            .addGroup(jpanel2Layout.createSequentialGroup()
                                .addGap(7, 7, 7)
                                .addComponent(cmbTipoEmp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(21, 21, 21)
                        .addGroup(jpanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel9)
                            .addComponent(cmbHorario, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(jPanelUsuario, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jPanelUsuario.getAccessibleContext().setAccessibleName("\"Usuario\"");
        jPanelUsuario.getAccessibleContext().setAccessibleDescription("");

        btnGuardar.setText("Guardar");
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });

        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jpanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(btnBuscar)
                        .addGap(245, 245, 245)
                        .addComponent(btnGuardar)
                        .addGap(39, 39, 39)
                        .addComponent(btnLimpiar))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 724, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(65, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(7, 7, 7)
                .addComponent(jpanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnBuscar)
                    .addComponent(btnGuardar)
                    .addComponent(btnLimpiar))
                .addGap(26, 26, 26)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(37, Short.MAX_VALUE))
        );

        jpanel2.getAccessibleContext().setAccessibleName("Datos Empleado");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 8, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 28, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

 public boolean valido(){
        
        boolean nombreEmp = Validaciones.validarNombre(txtNombre.getText());
        boolean apPaterno = Validaciones.validarNombre(txtApellidoPaterno.getText());
        boolean apMaterno = Validaciones.validarNombre(txtApellidoMaterno.getText());
        boolean usuario = Validaciones.validarNombre(txtUsuario.getText());
        
        boolean b = false;
        
        String n1 = "";
        String n2="";
        String n3 = "";
        String n4="";
        String n5 = "";
        String n6="";
        String n7="";
        String n8="";
        String n9 = "";
        String n10="";
        String n11 = "";
        String n12="";
        String n13="";
        
     if (!txtNombre.getText().isEmpty() && !txtApellidoPaterno.getText().isEmpty()
             && !txtApellidoMaterno.getText().isEmpty() && !txtNumeroDocumento.getText().isEmpty()
             && (radioDni.isSelected() || RadioCarnetExtranjeria.isSelected())
             && ((cmbTipoEmp.getSelectedItem().toString().equals("ADMINISTRADOR")) ? ((!txtUsuario.getText().isEmpty() && !txtPassword.getText().isEmpty() && !txtRespuesta.getText().isEmpty()
             && (cmbPregunta.getSelectedIndex() != 0)) ? true : false) : true)) {
         
         b = true;
     }
     else{
         
             b = false;
             n13 ="Los campos no deben estar vacios";
     }
        
     if(RadioCarnetExtranjeria.isSelected() && txtNumeroDocumento.getText().isEmpty()){
            b = false;
            n1 = "Ingresar numero de Pasaporte";
        }
        if(radioDni.isSelected() && txtNumeroDocumento.getText().isEmpty()){
             b = false;
             n2 = "Ingresar numero de DNI";
        }
          if(radioDni.isSelected() && txtNumeroDocumento.getText().length()!=8 && !txtNumeroDocumento.getText().isEmpty()){
           b = false;
           n3 = "DNI debe tener 8 digitos";
        }
            if(RadioCarnetExtranjeria.isSelected() && txtNumeroDocumento.getText().length()!=11 && !txtNumeroDocumento.getText().isEmpty() ){
          b = false;
          n4 =  "Pasaporte debe tener 11 digitos";
        }
            
        if(cmbTipoEmp.getSelectedIndex()<1){
            b = false;
            n5 = "Seleccionar Tipo Empleado";
        }
        
         if(cmbHorario.getSelectedIndex()<1){
            b = false;
           n6 =  "Seleccionar Horario";
        }
         
         if(!nombreEmp && !txtNombre.getText().isEmpty()){
           b = false;
           n7 =  "Error en el nombre de Empleado";
             
         }
         
                  
          if(!apPaterno && !txtApellidoPaterno.getText().isEmpty()){
           b = false;
           n8 =  "Error en el Apellido Paterno";
             
         }
          
           if(!apMaterno && !txtApellidoMaterno.getText().isEmpty()){
           b = false;
           n9 =  "Error en el Apellido Materno";
             
         }
       
         
         if  ((cmbTipoEmp.getSelectedItem().toString().equals("ADMINISTRADOR"))?((!txtUsuario.getText().isEmpty() && 
                  (valUsuario==0))?true:false):false){
           b = false;
           n10 =  "Verificar disponibilidad de usuario" ;
         }
            
           if  ((cmbTipoEmp.getSelectedItem().toString().equals("ADMINISTRADOR"))?((cmbPerfil.getSelectedIndex()<1)?true:false):false){
           b = false;
           n11 =  "Debe seleccionar un perfil" ;
         }
         
         if  ((cmbTipoEmp.getSelectedItem().toString().equals("ADMINISTRADOR"))?((cmbPregunta.getSelectedIndex()<1)?true:false):false){
           b = false;
           n12 =  "Debe seleccionar una Pregunta" ;
         }
        
       
         
          String rpta="";
         if (n13!="") rpta = rpta+ n13 + "\n";
         if (n1!="") rpta = rpta+ n1 + "\n";
         if (n2!="") rpta = rpta+ n2 + "\n";
         if (n3!="") rpta = rpta+ n3 + "\n";
         if (n4!="") rpta = rpta+ n4 + "\n";
         if (n5!="") rpta = rpta+ n5 + "\n";
         if (n6!="") rpta = rpta+ n6 + "\n";
         if (n7!="") rpta = rpta+ n7 + "\n";
         if (n8!="") rpta = rpta+ n8 + "\n";
         if (n9!="") rpta = rpta+ n9 + "\n";
         if (n10!="") rpta = rpta+ n10 + "\n";
         if (n11!="") rpta = rpta+ n11 + "\n";
         if (n12!="") rpta = rpta+ n12 + "\n";
         
                
         if (rpta!="")
         JOptionPane.showMessageDialog(null, "Errores: \n" + rpta );
         
        
        return b;
    }
    
    private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
       


        if (valido()) {

            String tipo = "";
            if (radioDni.isSelected()) {
                tipo = "DNI";
            } else if (RadioCarnetExtranjeria.isSelected()) {
                tipo = "Pasaporte";
            }
            Date fecha = fechaNac.getDate();
            String horario = new String();

            if (cmbHorario.getSelectedItem().toString().equals("MAÑANA")) {
                horario = "HOR000001";
            }
            if (cmbHorario.getSelectedItem().toString().equals("NOCHE")) {
                horario = "HOR000002";
            }


            Personal np = new Personal(txtIdEmpleado.getText(), txtNombre.getText(), txtApellidoPaterno.getText(), txtApellidoMaterno.getText(), tipo, txtNumeroDocumento.getText(), fecha, horario, "ACTIVO", cmbTipoEmp.getSelectedItem().toString());
            //Usuario nu = new Usuario(txtUsuario.getText(), txtPassword.getText(),txtIdEmpleado.getText());


            if (txtIdEmpleado.getText().isEmpty()) {


                try {
                    Controlador.Service.RRHH.GestionRRHH.agregarPersonal(np);
                    JOptionPane.showMessageDialog(this, "Se ha guardado correctamente", "Confirmación", JOptionPane.INFORMATION_MESSAGE);

                } catch (Exception ex) {

                    Logger.getLogger(NuevoEmpleado.class.getName()).log(Level.SEVERE, null, ex);
                }

              
                if (cmbTipoEmp.getSelectedItem().toString().equals("ADMINISTRADOR")) {

                    String usuario = txtUsuario.getText();
                    String password = new String(txtPassword.getPassword());
                    String estado = "ACTIVO";
                    String idEmpAdm = np.getIdEmpleado();

                    int indiceP = cmbPregunta.getSelectedIndex();



                    String idPregunta;

                    if (indiceP > 0) {
                        idPregunta = preguntas.get(indiceP - 1).getIdPregunta();
                    } else {
                        idPregunta = preguntas.get(indiceP).getIdPregunta();
                    }


                    String respuesta;

                    respuesta = txtRespuesta.getText();


                    Usuario nu = new Usuario(usuario, password, idEmpAdm, fecha, estado, idPregunta, respuesta);

                    Controlador.Service.RRHH.GestionRRHH.agregarUsuario(nu);

                    String perfil = cmbPerfil.getSelectedItem().toString();

                    int indice = cmbPerfil.getSelectedIndex(); //0 = "SELECCIONAR", 1 = "Administrador", 2 = "Trabajador", 3 = "Mantenimiento"

                    String idPerfil;

                    if (indice > 0) {
                        idPerfil = perfiles.get(indice - 1).getIdPerfil();
                    } else {
                        idPerfil = perfiles.get(indice).getIdPerfil();
                    }

                    String idUsuario = nu.getIdUsuario();
                    Date fechaU = new Date();
                    String estadoU = "ACTIVO";
                    PerfilxUsuario npxu = new PerfilxUsuario(idPerfil, idUsuario, fechaU, estadoU);
                    Controlador.Service.RRHH.GestionRRHH.agregarPerfilxUsuario(npxu);

                    //DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
                    //java.text.SimpleDateFormat sdf=new java.text.SimpleDateFormat("dd-MM-yyyy");
                
                }



            } else {

                String SacaId = (txtIdEmpleado.getText().substring(0, 3));

                //System.out.println(SacaId);
                if (SacaId.equals("EMP")) {
                    Controlador.Service.RRHH.GestionRRHH.actualizarPersonal(np);


                } else if (SacaId.equals("ADM")) {
                    Controlador.Service.RRHH.GestionRRHH.actualizarPersonal2(np);
                    String usuario = txtUsuario.getText();
                    String password = new String(txtPassword.getPassword());
                    String estado = "ACTIVO";
                    String idEmpAdm = np.getIdEmpleado();

                    int indiceP = cmbPregunta.getSelectedIndex();



                    String idPregunta;

                    if (indiceP > 0) {
                        idPregunta = preguntas.get(indiceP - 1).getIdPregunta();
                    } else {
                        idPregunta = preguntas.get(indiceP).getIdPregunta();
                    }


                    String respuesta;

                    respuesta = tb.data.get(indiceP - 1).getRespuesta();


                    Usuario nu = new Usuario(usuario, password, idEmpAdm, fecha, estado, idPregunta, respuesta);

                    //Usuario nu = new Usuario(usuario, password, idEmpAdm, fecha, estado);

                    Controlador.Service.RRHH.GestionRRHH.actualizarUsuario(nu);

                    String idUsuario = Controlador.Service.RRHH.GestionRRHH.obteneridUsuario(idEmpAdm);


                    //String idUsuario = nu.getIdUsuario();
                    Date fechaU = new Date();
                    String estadoU = "ACTIVO";
                    String perfil = cmbPerfil.getSelectedItem().toString();



                    int indice = cmbPerfil.getSelectedIndex(); //0 = "SELECCIONAR", 1 = "Administrador", 2 = "Trabajador", 3 = "Mantenimiento"

                    String idPerfil;

                    if (indice > 0) {
                        idPerfil = perfiles.get(indice - 1).getIdPerfil();
                    } else {
                        idPerfil = perfiles.get(indice).getIdPerfil();
                    }

                    PerfilxUsuario npxu = new PerfilxUsuario(idPerfil, idUsuario, fechaU, estadoU);

                    Controlador.Service.RRHH.GestionRRHH.actualizarPerfil(npxu);


                }
                JOptionPane.showMessageDialog(this, "Se ha actualizado correctamente", "Confirmación", JOptionPane.INFORMATION_MESSAGE);
            }


            tb.actualizarTabla();
            txtIdEmpleado.setText("");
            txtNombre.setText("");
            txtApellidoPaterno.setText("");
            txtApellidoMaterno.setText("");
            txtNumeroDocumento.setText("");
            txtUsuario.setText("");
            txtPassword.setText("");
            cmbPerfil.setSelectedIndex(0);
            fechaNac.setEditable(true);
            fechaNac.setDate(new Date());
            cmbHorario.setEnabled(true);
            cmbHorario.setSelectedIndex(0);
            cmbTipoEmp.setEnabled(true);
            cmbTipoEmp.setSelectedIndex(0);
            jPanelUsuario.setVisible(false);
            txtUsuario.setBackground(Color.WHITE);



        }
        // TODO add your handling code here:
    }//GEN-LAST:event_btnGuardarActionPerformed

    private void cmbTipoEmpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTipoEmpActionPerformed
        // TODO add your handling code here:
//         tipo = (String)cmbTipoEmp.getSelectedItem();
//         
//         if (tipo.equals("ADMINISTRADOR")){
//                    txtUsuario.setVisible(true);
//                    txtPassword.setVisible(true);
//              }
    }//GEN-LAST:event_cmbTipoEmpActionPerformed

    private void fechaNacActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fechaNacActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_fechaNacActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        // TODO add your handling code here:
        
        BuscarPersonal bP = new BuscarPersonal(this);
        Main.getDesktop().add(bP);
        bP.setVisible(true);
        
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void tblEmpleadosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblEmpleadosMouseClicked
              
//        // TODO add your handling code here:
        
        int selectedRowIndex = tblEmpleados.getSelectedRow(); //@return the index of the first selected row
        int selectedColumnIndex = tblEmpleados.getSelectedColumn(); //return the index of the first selected column
           if(selectedColumnIndex!=9){
            String selectId = (String) tblEmpleados.getValueAt(selectedRowIndex, 0);
             if(clic == 1 && selectedId.compareTo(selectId)==0){
                txtIdEmpleado.setText((String)tblEmpleados.getValueAt(selectedRowIndex, 0));
                txtNombre.setText((String)tblEmpleados.getValueAt(selectedRowIndex, 1));
                txtApellidoPaterno.setText((String)tblEmpleados.getValueAt(selectedRowIndex, 2));
                 txtApellidoMaterno.setText((String)tblEmpleados.getValueAt(selectedRowIndex, 3));
                 txtNumeroDocumento.setText(((String)tblEmpleados.getValueAt(selectedRowIndex, 4)).toString());
                 //Date fecNac = new Date();
                 //fecNac.(Date.parse(tblEmpleados.getex, 4).toString()));ValueAt(selectedRowIndex, 4).toString()));
                 Date fecNac = tb.data.get(selectedRowIndex).getFechaNacimiento();
                 fechaNac.setDate(fecNac);
                 int indice =0; 
                 String hor= ((String)tblEmpleados.getValueAt(selectedRowIndex, 7)).toString();
                 
                 if (hor.equals("MAÑANA")) {
                     indice = 1;
                 } else {
                     indice = 2;
                 }
      
               
                 cmbHorario.setSelectedIndex(indice);
                 
                 int indice2 =0;
                 
                 String tipo= ((String)tblEmpleados.getValueAt(selectedRowIndex, 8)).toString();
                 
                 if (tipo.equals("ADMINISTRADOR")) {
                     indice2 = 1;
                 } else {
                     indice2 = 2;
                 }
                 cmbTipoEmp.setSelectedIndex(indice2);
                 
                 String usu = tb.data.get(selectedRowIndex).getUsuario();
                 String pass = tb.data.get(selectedRowIndex).getPassword();
                 String perfil = tb.data.get(selectedRowIndex).getPerfil();
                 String tipod= tb.data.get(selectedRowIndex).getTipoDocumento();
                 String pregunta = preguntas.get(selectedRowIndex).getPregunta();
                 String respuesta = tb.data.get(selectedRowIndex).getRespuesta();
                 
                 
                 
                 
                 if (tipod.equals("DNI"))
                   {
                   radioDni.setSelected(true);
           
                   }
                 
                 else {RadioCarnetExtranjeria.setSelected(true);
             
                 }
                 
                 txtUsuario.setText(usu);
                 txtPassword.setText(pass);
                 txtPassword.setEditable(false);
                 cmbPerfil.setSelectedItem(perfil);
                 cmbPregunta.setSelectedItem(pregunta);
                 txtRespuesta.setText(respuesta);
                 
                 //buscar Usuario, password, perfil
                 
                 //txtUsuario.setText("");
                        
                 //cmbPerfil.setSelectedIndex(indice2);        
                 
                // final Calendar instance  = Calendar.getInstance();
 //                Date date= (Date)tblEmpleados.getValueAt(selectedRowIndex, 4);
//                 instance.set(2012, 01, 2006);
//                 Date date = instance.getTime();
//                 fechaNac.setDate(date);
                 //cmbTipo.setSelectedItem(tblProductos.getValueAt(selectedRowIndex, 5));
//                cmbTipo.setSelectedIndex(Integer.parseInt((String)tblProductos.getValueAt(selectedRowIndex, 6)));
                 clic = 0;            
//                cmbTipo.setEnabled(false);
                }else if(clic == 0){
                    selectedId = selectId;
                    clic++;
                }else{
                    clic = 0;
                }
            }else{ //ACA ELIMINO PRODUCTOS
                int confirmado = JOptionPane.showConfirmDialog(this,"¿Desea eliminar el empleado?");
                if (confirmado == JOptionPane.OK_OPTION){
                    
             String SacaId = ((String)tblEmpleados.getValueAt(selectedRowIndex, 0)).substring(0, 3);

            System.out.println(SacaId);
            if (SacaId.equals("EMP")) {
                Controlador.Service.RRHH.GestionRRHH.eliminarPersonal((String)tblEmpleados.getValueAt(selectedRowIndex, 0));
            } else if (SacaId.equals("ADM")) {
                //System.out.println("entre");
               Controlador.Service.RRHH.GestionRRHH.eliminarPersonal2((String)tblEmpleados.getValueAt(selectedRowIndex, 0));
            }
                    
                
                tb.actualizarTabla();
            }                
       }
                                
    }//GEN-LAST:event_tblEmpleadosMouseClicked

    private void cmbHorarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbHorarioActionPerformed
        // TODO add your handling code here:
        
        
    }//GEN-LAST:event_cmbHorarioActionPerformed

    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
          
        txtIdEmpleado.setEditable(false);
        txtIdEmpleado.setText("");
        txtNombre.setText("");
        txtApellidoPaterno.setText("");
        txtApellidoMaterno.setText("");        
        txtNumeroDocumento.setText("");
        
        cmbHorario.setSelectedItem("SELECCIONAR");
        fechaNac.setDate(new Date());
        cmbTipoEmp.setSelectedItem("SELECCIONAR");
        cmbPerfil.setSelectedItem("Seleccionar");
        
        txtUsuario.setText("");
        txtPassword.setText("");
        txtUsuario.setBackground(Color.WHITE);
        
        //radioDni.setSelected(false);
        //RadioCarnetExtranjeria.setSelected(true);
        
        
        // TODO add your handling code here:
    }//GEN-LAST:event_btnLimpiarActionPerformed

    private void txtPasswordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtPasswordActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtPasswordActionPerformed

    private void btnCheckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCheckActionPerformed
    String usuario = txtUsuario.getText();
    String user = Controlador.Service.Seguridad.ServicioSeguridad.VerificarUsuario(usuario);
        
    if (user  == null ){
        JOptionPane.showMessageDialog(this, "UsuarioDisponible", "Confirmación", JOptionPane.INFORMATION_MESSAGE);  
        txtUsuario.setBackground(Color.green);
        valUsuario = 1;
    }
    
    else{
        JOptionPane.showMessageDialog(this, "Seleccionar otro usuario por favor", "Confirmación", JOptionPane.INFORMATION_MESSAGE); 
        txtUsuario.setBackground(Color.red);
        valUsuario = 0;
    }
    
        // TODO add your handling code here:
    }//GEN-LAST:event_btnCheckActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JRadioButton RadioCarnetExtranjeria;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCheck;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JComboBox cmbHorario;
    private javax.swing.JComboBox cmbPerfil;
    private javax.swing.JComboBox cmbPregunta;
    private javax.swing.JComboBox cmbTipoEmp;
    private org.jdesktop.swingx.JXDatePicker fechaNac;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanelUsuario;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel jlabel6;
    private javax.swing.JPanel jpanel2;
    private javax.swing.JLabel lblPassword;
    private javax.swing.JLabel lblPerfil;
    private javax.swing.JLabel lblUsuario;
    private javax.swing.JRadioButton radioDni;
    private javax.swing.JTable tblEmpleados;
    private javax.swing.JTextField txtApellidoMaterno;
    private javax.swing.JTextField txtApellidoPaterno;
    private javax.swing.JTextField txtIdEmpleado;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtNumeroDocumento;
    private javax.swing.JPasswordField txtPassword;
    private javax.swing.JTextField txtRespuesta;
    private javax.swing.JTextField txtUsuario;
    // End of variables declaration//GEN-END:variables
}
